using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UISerialAnimation : UIAnimationElement
{
	public List<UIAnimationElement> elements = new List<UIAnimationElement>();

	protected Coroutine myCoroutine;

	public override void Play()
	{
		Stop();
		base.Play();
		myCoroutine = StartCoroutine(DoSerial());
	}

	public override void Stop()
	{
		base.Stop();
		if (myCoroutine != null)
		{
			StopCoroutine(myCoroutine);
		}
	}

	private IEnumerator DoSerial()
	{
		float time = 0f;
		foreach (UIAnimationElement element in elements)
		{
			element.Play();
			while (element.isPlaying)
			{
				yield return null;
			}
		}
		OnEnd();
	}
}
